package com.sgb.kjwl.view.ui.adapter.material;

import android.content.Context;
import android.text.TextUtils;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.ConcreteFilterEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class ConcreteParamsAdapter extends BaseRecycleAdapter<ConcreteFilterEntity> {

    private int index = -1;

    public ConcreteParamsAdapter(Context context, List<ConcreteFilterEntity> data) {
        super(context, R.layout.item_concrete_params, data);

        for (int i = 0; i < data.size(); i++) {
            if (!TextUtils.isEmpty(data.get(i).getIsChoose()) && data.get(i).getIsChoose().equals("1")) {
                index = i;
            }
        }
    }

    @Override
    public void convert(ItemViewHolder holder, ConcreteFilterEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView value = holder.itemView.findViewById(R.id.value);


        if (index != holder.getPosition()) {
            value.setTextColor(context.getResources().getColor(R.color.color_666666));
            value.setBackground(context.getResources().getDrawable(R.drawable.corner2_f5f5f5_bg));
        } else {
            value.setTextColor(context.getResources().getColor(R.color.color_main));
            value.setBackground(context.getResources().getDrawable(R.drawable.corner2_105792fd_bg));
        }
    }

    public void setSelect(int i) {
        index = i;
    }

    public int getSelect() {
        return index;
    }
}
